package servlet;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import po.Dish;
import service.DishService;
import service.impl.DishServiceImpl;

/**
 * Servlet implementation class ShowDishServlet
 */
public class ShowDishServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ShowDishServlet() {
        super();
        // TODO Auto-generated constructor stub
    }
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    	doPost(request, response);
    }
	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setCharacterEncoding("UTF-8");
    	response.setHeader("content-type","text/html;charset=UTF-8");
    	List<Dish> dishList = new ArrayList<Dish>();
    	DishService dishServiceImpl = new DishServiceImpl();
    	dishList = dishServiceImpl.Query();
    	HttpSession session =  request.getSession();
    	session.setAttribute("dishList",dishList);
    	response.sendRedirect("index.jsp");
    	//request.getRequestDispatcher("index.jsp").forward(request, response);
	}

}
